package com.easybenefit.UUService.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.easybeanfit.UUService.commutill.UULoadPictureUtill;
import com.easybeanfit.UUService.commutill.UUToastUtil;
import com.easybeanfit.UUService.config.UUConfig;
import com.easybenefit.UUService.R;
import com.easybenefit.UUService.activity.CouponActivity;
import com.easybenefit.UUService.activity.CouponsDetailActivity;
import com.easybenefit.UUService.activity.MainActivity;
import com.easybenefit.UUService.model.PlatNewsBean;

import java.util.List;

/**
 * Created by  GJ on 2015/12/13.
 */
public class MainViewPagerAdapter extends PagerAdapter {
    private Matrix matrix = new Matrix();
    private Matrix savedMatrix = new Matrix();
    private List<PlatNewsBean> list;
    private ImageView img;
    static final int NONE = 0;

    private Context context;

    public MainViewPagerAdapter(List<PlatNewsBean> list, Context context) {
        this.list = list;

        this.context = context;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        //  super.destroyItem(container, position, object);
        try {
            container.removeView((View) object);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(final ViewGroup container, final int position) {
        try {

            if (position < list.size()) {
                container.addView(list.get(position).getView());
                View view = list.get(position).getView();

                view.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent=new Intent(context, CouponsDetailActivity.class);
                        intent.putExtra("type",true);
                        intent.putExtra("noWX",true);
                        intent.putExtra("url",list.get(position).getUrl());
                        context.startActivity(intent);
                    }
                });
                return list.get(position).getView();
            } else {
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }


}
